package com.ly.other.web;

import com.ly.damai.entity.User;
import org.springframework.web.bind.annotation.*;
import com.ly.bean.Result;

@RestController
@RequestMapping("fegin")
public class FeginDemoDo {

    @RequestMapping("add")
        // 服务端
    int add(@RequestParam("a") int a,
            @RequestParam("b") int b) {
        return a + b;
    }

    // 对象属性映射为请求参数名, 自动装箱
    @RequestMapping("res")
    Result res(Result result) {
        result.setCode(result.getCode() + 1);
        return result;
    }

    // 用户信息是通过 请求体 body 传递过来
    @RequestMapping("user")
    User user(@RequestBody User user,
              @RequestParam("myname") String myname){
        user.setUsername(myname);
        return user;
    }

    // RESTful 请求方式的地址参数
    @RequestMapping("/hello/{nm}")
    String hello(@PathVariable("nm") String name) {
        return "你好 " + name;
    }


}
